import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test_qq/dataBase.dart';
import 'package:flutter_test_qq/updatePwd.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
class myPage extends StatefulWidget{

  final String Name;
  final String Pic;
  myPage({Key? key, required this.Name, required this.Pic,}) : super(key: key);

  @override
  State<StatefulWidget> createState()=>myPageState();

}

class myPageState extends State<myPage>{
  final picker = ImagePicker();
  File? _imgPath;




  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    get();
  }
  String get Name => widget.Name;
  String get Pic => widget.Pic;
  var qqName ='';
  var qqPic ='';

  Future getImage(bool isTakePhoto) async {
    try {
      var pickedFile = await picker.getImage(
          source: isTakePhoto ? ImageSource.camera : ImageSource.gallery);
      if (pickedFile != null) {
        setState(() {
          _imgPath = File(pickedFile.path);
        });
      } else {
        print('没有选择任何图片');
      }
    } catch (e) {
      print("该手机不支持相机");
    }
  }
  List itemsList=[
    {
      "icon":"images/Icons/1.png",
      "title":'直播',
    },
    {
      "icon":"images/Icons/2.png",
      "title":'我的QQ钱包',
    },
    {
      "icon":"images/Icons/3.png",
      "title":'装扮我的QQ',
    },
    {
      "icon":"images/Icons/4.png",
      "title":'我的收藏',
    },
    {
      "icon":"images/Icons/5.png",
      "title":'我的相册',
    },
    {
      "icon":"images/Icons/6.png",
      "title":'我的文件',
    },
  ];

  Widget getData(context,index){
    return ListTile(
      title: Text(itemsList[index]['title']),
      leading: Image(image: AssetImage(itemsList[index]['icon']),width:30,height:30),
      trailing: Icon(Icons.keyboard_arrow_right),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // body: getListView(),
      body: Column(
        children: [
          SizedBox(
            child: Stack(
              alignment: FractionalOffset(0.5,0.7),
              children: [
                Image.asset('images/pic4.jpg',fit: BoxFit.cover,width: 600),
                Container(
                  color: Colors.black.withOpacity(0.3),
                ),
                Positioned(
                    top: 43,
                    left: 15,
                    child: Row(
                      children: [
                        SizedBox(
                          width: 80,
                          height:80,
                          child: CircleAvatar(backgroundImage: AssetImage(this.Pic)),
                        ),
                        SizedBox(width: 20,),
                        Text((this.Name==null?qqName:this.Name),style: TextStyle(
                          color: Colors.white,
                          fontSize: 30
                        ),),
                      ],
                    ),
                ),
              ],
            ),
            width: 420,
            height: 150,
          ),
          Container(
            width: 350,
            height: 350,
            child:  ListView.builder(
                itemCount: itemsList.length,
                itemBuilder: this.getData,
              )
          ),
          SizedBox(height:20,),
          SizedBox(
            height: 60,
            width: 300,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // Text('设置'),
                SizedBox(
                    child: Row(
                      children: [
                        TextButton(
                          onPressed:(){
                            print('进入修改密码页面');
                            Navigator.of(context)
                                .push(MaterialPageRoute(builder: (BuildContext context) {
                              return updatePwd();

                            }));},
                          child: Text('修改密码'),
                        ),
                      ],
                    )
                ),
                Text('夜间'),
                Text('等级'),
                Text('天气'),
              ],
            ),
          ),
        ],
      ),
    );
  }

}